#region Copyright (c) 2000-2011 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{                                                                   }
{                                                                   }
{       Copyright (c) 2000-2011 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2010 Developer Express Inc.

namespace DevExpress.OAuth {
    using System;
    using System.Collections.Generic;
    using System.Text;

    public static partial class Signing {
        public static class PlainText {

            /// <summary>
            /// 9.4.1.  Generating Signature
            /// oauth_signature is set to the concatenated encoded values of the Consumer Secret and Token Secret, separated by a ‘&’ 
            /// character (ASCII code 38), even if either secret is empty. The result MUST be encoded again.
            /// These examples show the value of oauth_signature for Consumer Secret djr9rjt0jd78jf88 and 3 different Token Secrets:
            /// 
            /// jjd999tj88uiths3: oauth_signature=djr9rjt0jd78jf88%26jjd999tj88uiths3
            /// jjd99$tj88uiths3: oauth_signature=djr9rjt0jd78jf88%26jjd99%2524tj88uiths3
            ///            Empty: oauth_signature=djr9rjt0jd78jf88%26
            /// </summary>

            public static Parameter Sign(string consumerSecret, string tokenSecret) {
                StringBuilder signature = new StringBuilder();

                if (!String.IsNullOrEmpty(consumerSecret)) {
                    signature.Append(Escaping.Escape(consumerSecret));
                }

                signature.Append("&");

                if (!String.IsNullOrEmpty(tokenSecret)) {
                    signature.Append(Escaping.Escape(tokenSecret));
                }

                return new Parameter(
                                "oauth_signature",
                                Escaping.Escape(signature.ToString()));
            }
                
            public static void Sign(string consumerSecret, string tokenSecret,
                        ICollection<Parameter> authParams) {

                if (authParams == null) {
                    throw new ArgumentNullException("params");
                }

                authParams.Add(Sign(consumerSecret, tokenSecret));

            }
        }
    }

}